package command;

import server.KVMessage.StatusType;
import util.IKeyValueStorage;

public class CommandGet implements ICommand {
	private IKeyValueStorage storage;
	private String key;
	
	public CommandGet(IKeyValueStorage storage, String key) {
		this.key = key;
		this.storage = storage;
	}
	
	@Override
	public String execute() {
		if (!storage.containsKey(key) ) {
			return ClientInputHandler.composeClientResponse(StatusType.GET_ERROR, "no value for key "+key, "");
		}
		String value = (String) storage.get(key);
		return ClientInputHandler.composeClientResponse(StatusType.GET_SUCCESS, value, "");
	}
}
